﻿using SpiderStudy.Utils.Currency;
using SpiderStudy.Utils.Currency.FileUtils;
using SpiderStudy.Utils.Helper;
using SpiderStudy.WebSite.DataHelper;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace SpiderStudy.ViewManage
{
    public partial class KeysExcavateControl : UserControl
    {
        public KeysExcavateControl()
        {
            InitializeComponent();
            InitView();
        }

        private static String ExcluedeFilePath = StaticValue.BinPath + "TitleExclude.txt";
        private static List<string> TempExcluede = FileHelper.ReadAllLine(ExcluedeFilePath);

        /// <summary>
        /// 这是combobox的帮助，选择模式
        /// </summary>
        private static bool ModeFlag = false;

        private void InitView()
        {
            FileHelper.FileExits(ExcluedeFilePath, true);
            comboBox1.Items.AddRange(new String[] { "替换模式", "排除模式" });
            comboBox1.SelectedIndex = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new WebSite.Spider360.ExcavateKeys().SaveTitleList(textBox1.Text, TextHelper.StringToInt(numberTextbox1.Text));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FileHelper.AppendUTF8Text(ExcluedeFilePath, textBox2.Text);
            TempExcluede.Add(textBox2.Text);
            textBox2.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new DataClear().FileClear(FileHelper.SelectFile(), TempExcluede, ModeFlag);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.Text)
            {
                case "替换模式":
                    ModeFlag = true;
                    break;

                case "排除模式":
                    ModeFlag = false;
                    break;
            }
        }
    }
}